package com.md.rps.action.actions;

import com.md.rps.mybatis.model.USER;
import com.md.rps.service.UserOperator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserAction {

    @Autowired
    private UserOperator userOperator;

    @GetMapping("login")
    public USER login(@RequestParam("openid") String openid,
                      @RequestParam("unionid") String unionid) {
        return userOperator.getUserByID(1);
    }

    @GetMapping("getUserList")
    public List<USER> getUserList(@RequestParam("start")int start,
                                  @RequestParam("end")int end) {
        return userOperator.getUserList(start,end);
    }

    @GetMapping("getUserByID")
    public USER getUserByID(@RequestParam("userId")int id) {
        return userOperator.getUserByID(id);
    }

    @GetMapping("getUserByCard")
    public USER getUserByCard(@RequestParam("cardNo")String card) {
        return userOperator.getUserByCard(card);
    }

    @PostMapping("sign")
    public Integer sign(USER user) {
        return userOperator.addUser(user);
    }

    @PostMapping("updateUser")
    public Integer update(USER user) {
        return userOperator.updateUser(user);
    }

    @PostMapping("deleteUser")
    public Integer delete(@RequestParam("userId")int id) {
        return userOperator.deleteUser(id);
    }



}
